|
|
|
|
|
|
|
The two types of keyboard filters illustrated here (discard or convert) can be combined to form a powerful input validation tool. Let's create a validation example that allows only uppercase letters A through Z, or numerals 0 through 9no spaces or any other characters. |
|
|
|
|
|
|
|
|
First add a new label/textbox control pair. Set the label caption property to Combined. Set the textbox Name property to txtCombined and the text property to blank. Refer to Figure 5.3 for positioning and sizing information. |
|
|
|
|
|
|
|
|
Figure 5.3.
Adding the Combined
control to the form. |
|
|
|
|
|
|
|
|
Listing 5.4 shows how to combine a check against a valid list and a conversion of keystrokes into a single input validation. |
|
|
|
|
|
|
|
|
Listing 5.4. A single KeyPress event to check for valid entry and force uppercase. |
|
|
|
|
|
|
|
|
Private Sub txtCombined_KeyPress(KeyAscii As Integer)
'
Dim strValid As String
'
strValid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'
KeyAscii = Asc(UCase(Chr(KeyAscii)))
'
If KeyAscii > 26 Then
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
'
End Sub |
|
|
|
|
|